"ui";
ui.layout(
  <vertical margin="10">
    <com.google.android.material.textfield.TextInputLayout
      android:id="@+id/userInputLayout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
    >
      <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="22sp" />
    </com.google.android.material.textfield.TextInputLayout>
    <input w="*"></input>
  </vertical>
);

// 开启错误提示
ui.userInputLayout.setErrorEnabled(true);
// 开启计数
ui.userInputLayout.setCounterEnabled(true);
// 输入最大长度
ui.userInputLayout.setCounterMaxLength(10);
// 浮动标签文本
ui.userInputLayout.setHint("password");
// 启用或禁用密码可见性切换功能
ui.userInputLayout.setPasswordVisibilityToggleEnabled(true);

ui.userInputLayout.getEditText().addTextChangedListener(
  new android.text.TextWatcher({
    afterTextChanged: function (s) {
      if (ui.userInputLayout.getEditText().getText().toString().trim().length > 10) {
        ui.userInputLayout.setError("用户名长度超出限制");
      } else {
        ui.userInputLayout.setError(null);
      }
    },
  })
);
